﻿@{
    ViewBag.Title = "SchoolInfoList";
    Layout = "~/Views/Shared/_BasicLayout.cshtml";
}

<script type="text/javascript">
    $(function () {
        var height = $("#divTotal").height();
        var master = $("#master").height();
        var content = parseFloat(height) - parseFloat(master) - 30;
        $("#tbList").css("height", content);

        $("#tbList").datagrid({
            url: '/SchoolInfo/List',
            loadMsg: '数据加载中请稍后……',
            pagination: true,
            rownumbers: true,
            idField: "ID",
            columns: [[
                  { field: 'ck', checkbox: true, width: 30 },
                  { field: 'ID', title: 'ID', width: 80, align: "center", hidden: true },
                {
                    field: 'SchoolCode', title: '校区编码', sortable: true, width: 80, align: "center"
                    //, editor: {
                    //    type: "validatebox",
                    //    options: {
                    //        required: true
                    //    }
                    //}
                },
                {
                    field: 'SchoolName', title: '校区名称', sortable: true, width: 200, align: "center", editor: {
                        type: "validatebox",
                        options: {
                            required: true
                        }
                    }
                },
                  {
                      field: 'IfHeadquarters', title: '是否父校区', sortable: true, width: 100, align: "center",
                      editor: {
                          type: "combobox",
                          options: {
                              editable: false,
                              required: true,
                              data: StaticCombo.YesorNo,
                              valueField: 'value',
                              textField: 'text',
                          }
                      },
                      formatter: function (value, row, index) {
                          return com.getArrayText(StaticCombo.YesorNo, value);
                      }
                  },
                  {
                      field: 'ParentId', title: '父校区名称', width: 100, align: "center", formatter: function (value, row, index) {
                          return row.ParentName
                      }, editor: {
                          type: "combobox",
                          options: {
                              url: '/SchoolInfo/GetParentSchool',
                              valueField: 'value',
                              textField: 'text',
                              required: true
                          }
                      }
                  },
                {
                    field: 'SchoolAddress', title: '校区地址', sortable: true, width: 200, align: "center", editor: {
                        type: "validatebox",
                        options: {
                            required: true
                        }
                    }
                },
                {
                    field: 'HeadNameList', title: '负责人', sortable: true, width: 200, align: "center"
                },
                {
                    field: 'EditPerName', title: '编辑人', sortable: true, width: 100, align: "center"
                },
                {
                    field: 'EditTime', title: '编辑时间', sortable: true, width: 150, align: "center"
                },
                {
                    field: 'Note', title: '备注', sortable: true, width: 200, align: "center", editor: {
                        type: "textbox",
                        options: {
                        }
                    }
                },
                { field: 'DelState', title: '', hidden: true }
            ]],
            singleSelect: true,
            pageSize: 10,
            remoteSort: false,//是否从服务器排序
            queryParams: com.serializeSearchArray("form1"),
            pageList: [10, 20, 30],
            striped: true,
            noheader: true,
            onAfterEdit: function (rowIndex, rowData, changes) {
                if (editAction == "edit") {
                    com.ajax({
                        url: "/SchoolInfo/EditSchoolInfo",
                        data: rowData,
                        success: function (data) {
                            com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                        }
                    });
                }
                else if (editAction == "add") {
                    com.ajax({
                        url: "/SchoolInfo/AddSchoolInfo",
                        data: rowData,
                        success: function (data) {
                            com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                        }
                    });
                }
                editRow = undefined;
            },
            onCancelEdit: function (rowIndex, rowData) {
                $("#tbList").datagrid("rejectChanges");
            }
        });
    });


    editRow = undefined;
    editAction = undefined;
    //查询
    function funcSearch() {
        var para = com.serializeSearchArray("form1");
        $("#tbList").datagrid("load", para);
    }
    function funcAdd() {
        //添加时先判断是否有开启编辑的行，如果有则把开户编辑的那行结束编辑
        if (editRow != undefined) {

        }
        //添加时如果没有正在编辑的行，则在datagrid的第一行插入一行
        if (editRow == undefined) {
            $("#tbList").datagrid("insertRow", {
                index: 0, // index start with 0
                row: {
                }
            });
            //将新插入的那一行开启编辑状态
            $("#tbList").datagrid("beginEdit", 0);
            //给当前编辑的行赋值
            editRow = 0;
            editAction = "add";
        }
    }
    function funcEdit() {
        var row = $('#tbList').datagrid('getSelected');

        if (row) {
            if (editRow != undefined) {
            }
            else {
                var index = $("#tbList").datagrid('getRowIndex', row);
                //  console.log(index);
                $("#tbList").datagrid('beginEdit', index);
                editAction = "edit";
                editRow = index;
                rowData = $("#tbList").datagrid("getSelected");
            }
        }
        else {
            com.message("information", "请选中需要修改的行");
        }
    }
    function funcRemove() {
        $.messager.confirm('确认对话框', '您确定删除该数据吗？', function (r) {
            if (r) {
                var rowData = $("#tbList").datagrid("getSelected");
                if (rowData) {
                    com.ajax({
                        url: '/SchoolInfo/DelSchoolInfo',
                        data: { Id: rowData.ID },
                        success: function (data) {
                            com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); })
                        }
                    });
                }
                else {
                    com.message("information", "请选中需要删除的行！");
                }
            }
        });
    }
    //保存
    function funcSave() {
        $('#tbList').datagrid('endEdit', editRow);
    }
    //取消编辑
    function funcCancel() {
        $('#tbList').datagrid("cancelEdit", editRow);
        editRow = undefined;
        editAction = undefined;
    }
    //重置
    function funcReload() {
        $("#form1").form("reset");
        var para = com.serializeSearchArray("form1");
        $("#tbList").datagrid("load", para);
        funcCancel();
    }
    function funcSelectPeo() {
        var row = $('#tbList').datagrid('getSelected');
        if (row) {
            $.extend(com.dialogObj, { title: "分配负责人", width: 500, height: 300, href: "/BD/User/AssignComboPeoWindowBySchool"});
            $("#assignComboPeo").dialog(
               com.dialogObj
            );
            $(top.document).find("#hidId").val(row.ID);
            $(top.document).find("#hidAction").val("SchoolHead");
            $(top.document).find("#SchoolCode").val(row.SchoolCode);
        }
        else {
            com.message("information", "请选中一行");
        }
    }
</script>
<div id="divTotal" style="height: 100%; width: 100%">
    <div style="margin:5px" id="master">
        <form id="form1">
            <input id="SchoolCode" name="SchoolCode" class="easyui-textbox" data-options="prompt:'校区编码'" data-cp="co">
            <input id="SchoolName" name="SchoolName" class="easyui-textbox" data-options="prompt:'校区名'" data-cp="co">
            <input id="SchoolAddress" name="SchoolAddress" class="easyui-textbox" data-options="prompt:'校区地址'" data-cp="co">
            <input class="easyui-combobox" id="IfHeadquarters" name="IfHeadquarters" data-options="valuefield:'value',textfield:'text',data:StaticCombo.YesorNo,panelHeight:'auto'" style="width:120px" />
        </form>
    </div>
    <table id="tbList" title="校区信息表" style="width: 100%"></table>
</div>
<div id="assignComboPeo">
</div>
